#! /bin/bash
# ShadowsocksR Install shell script
userConfig="{\n
    \"server\": \"0.0.0.0\",\n
    \"server_ipv6\": \"::\",\n
    \"server_port\": 8383,\n
    \"local_address\": \"127.0.0.1\",\n
    \"local_port\": 1080,\n
\n
    \"password\": \"a3653987\",\n
    \"method\": \"aes-256-cfb\",\n
    \"protocol\": \"auth_aes128_md5\",\n
    \"protocol_param\": \"\",\n
    \"obfs\": \"http_simple\",\n
    \"obfs_param\": \"\",\n
    \"speed_limit_per_con\": 0,\n
    \"speed_limit_per_user\": 0,\n
\n
    \"additional_ports\" : {}, // only works under multi-user mode\n
    \"additional_ports_only\" : false, // only works under multi-user mode\n
    \"timeout\": 120,\n
    \"udp_timeout\": 60,\n
    \"dns_ipv6\": false,\n
    \"connect_verbose_info\": 0,\n
    \"redirect\": \"\",\n
    \"fast_open\": false\n
}\n
"
yum install -y git python setuptools zlib zlib-devel  easy_install pip
rm -Rf /usr/local/src/shadowsocksr
git clone https://git.oschina.net/leuchtturm/ssr.git /usr/local/src/shadowsocksr
cd /usr/local/src/shadowsocksr/
bash initcfg.sh
echo -e $userConfig > /usr/local/src/shadowsocksr/user-config.json
chmod +x /etc/rc.d/rc.local
isAutoStart=`cat /etc/rc.d/rc.local | grep /usr/local/src/shadowsocksr/shadowsocks/server.py`
if [ "$isAutoStart" = "" ];then
    echo "add Auto start to system /etc/rc.d/rc.local"
    echo "python /usr/local/src/shadowsocksr/shadowsocks/server.py -c /usr/local/src/shadowsocksr/user-config.json" >> /etc/rc.d/rc.local
fi